import { onMounted, reactive, toRefs } from 'vue'
import { allopts } from '@/api/public.js'
import { strHump } from '@/utils/index'

const isString = val =>
  Object.prototype.toString.call(val) === '[object String]'

const isArray = val => Object.prototype.toString.call(val) === '[object Array]'

export function useEnumSelect(props) {
  const { params } = props

  const data = reactive({
    options: {},
    loading: false,
  })

  const loadData = () => {
    data.loading = true
    data.options = {}

    let _params = params
    if (isString(_params)) {
      _params = [_params]
    }

    return allopts({ params: _params }).then(
      res => {
        const { data: _data } = res
        data.loading = false
        data.options = _data||{}
        return _data
      },
      err => {
        data.loading = false
        data.options = {}
        return Promise.reject(err)
      }
    )
  }

  onMounted(() => {
    loadData()
  })
console.log();
  return toRefs(data)
}
